/* websocket消息监听存储 */
export default {
	namespaced: true, // 使用命名空间
	state: {
		websocketMessages: [], // 存储 WebSocket 消息的数组
		myArray: new Array(1), //存储一条数据用来新用户数据初始化
	},
	mutations: {
		addWebsocketMessage(state, message) {
			var seenIds = new Set();
			state.websocketMessages = [...state.websocketMessages,...message];
			var newMessageList = state.websocketMessages.filter(item => {
				if (!seenIds.has(Number(item.message_id))) {
					seenIds.add(Number(item.message_id));
					return true;
				}
				return false;
			});
			state.websocketMessages = [...newMessageList];
		},
		clearWebsocketMessages(state) {
			state.websocketMessages = [];
		},
		updateMyArray(state, payload) {
			state.myArray = [...payload];
		},
	},
	actions: {
		receiveWebsocketMessage({
			commit
		}, message) {
			console.log("正在开始websocket消息存储--------》");
			console.log(message);
			commit('addWebsocketMessage', message);
		},
		updateArray({
			commit
		}, payload) {
			commit('updateMyArray', payload);
		},
	},
};